//
//  ZTThread.m
//  ZHYYTool
//
//  Created by MT-SW-005 on 2021/11/4.
//  Copyright © 2021 MT-SW-005. All rights reserved.
//

#import "ZTThread.h"

@implementation ZTThread

/*
 创建串行队列
 */
+(dispatch_queue_t)createSerialQueue
{
    dispatch_queue_t queue = dispatch_queue_create("Queue", DISPATCH_QUEUE_SERIAL);
    return queue;
}


/*
创建并行队列
*/
+(dispatch_queue_t)createConcurrentQueue
{
    dispatch_queue_t queue = dispatch_queue_create("Queue", DISPATCH_QUEUE_CONCURRENT);
    return queue;
}


/*
获取全局并行队列
*/
+(dispatch_queue_t)getGlobalQueue
{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    return queue;
}


/*
获取主队列
*/
+(dispatch_queue_t)getMainQueue
{
    dispatch_queue_t mainQueue = dispatch_get_main_queue();
    return mainQueue;
}



/*
 运行同步任务
 dispatch_sync(dispatch_queue_t queue, DISPATCH_NOESCAPE dispatch_block_t block);
 */
+ (void)runSyncWithQueue:(dispatch_queue_t)queue block:(DISPATCH_NOESCAPE dispatch_block_t)ablock
{
     dispatch_sync(queue,ablock);
}


/*
 运行异步任务
dispatch_async(dispatch_queue_t queue, DISPATCH_NOESCAPE dispatch_block_t block);
*/
+ (void)runAsyncWithQueue:(dispatch_queue_t)queue block:(DISPATCH_NOESCAPE dispatch_block_t)ablock
{
     dispatch_async(queue, ablock);
}


// NSthread
+(NSThread*)createThreadwithTarget:(id)target selector:(SEL)aSelector object:(nullable id)argument
{
    NSThread *thread = [[NSThread alloc]initWithTarget:target selector:aSelector object:argument];
    return thread;
}


+(NSThread*)createThreadwithBlock:(void (^)(void))block
{
    NSThread *thread = [[NSThread alloc]initWithBlock:block];
    return thread;
}


+(void)startThread:(NSThread*)thread
{
     [thread start];
}


+(void)cancelThread:(NSThread*)thread
{
     [thread cancel];
}


@end
